package pl.edu.pw.polygen.menu;

import javax.annotation.PostConstruct;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.Command;
import com.vaadin.ui.MenuBar.MenuItem;

/**
 * @author borysfan
 *
 */

@Scope("prototype")
@Component
public class TopMenuBar extends HorizontalLayout{

	private static final long serialVersionUID = -8074132919840752047L;
	
	private MenuBar menuBar;
	
	@Autowired
	private Command newProjectCommand;
	
	@Autowired
	private Command newFileCommand;
	
	@Autowired
	private Command saveCommand;
		
	@Autowired
	private Command logoutCommand;
	
	@Autowired
	private Command showAxisCommand;
	
	@Autowired
	private Command showGridCommand;
	
	@Autowired
	private Command aboutCommand;
	
	@Autowired
	private Command helpCommand;
	
	@Autowired 
	private Command boundaryIdicatorCommand;
	
	public TopMenuBar(){
		super();
		setWidth("100%");
		
		Logger.getLogger(TopMenuBar.class).debug("topMenuBar has been created");
	}
	
	@PostConstruct
	public void initialize(){
		menuBar = new MenuBar();
		menuBar.setWidth("100%");
		this.initFileItem();
		this.initEditItem();
		this.initViewItem();
		this.initToolsItem();
		this.initHelpItem();
		
		addComponent(menuBar);
	}
	
	private void initFileItem(){
		final MenuBar.MenuItem fileItem = menuBar.addItem("File", null);
		fileItem.addItem("New project", newProjectCommand);
		fileItem.addItem("New file", newFileCommand);
		fileItem.addItem("Save", saveCommand);
		fileItem.addItem("Logout",logoutCommand);
	}
	
	private void initEditItem(){
		final MenuBar.MenuItem editItem = menuBar.addItem("Edit", null);
	}
	
	private void initViewItem(){
		final MenuBar.MenuItem viewItem = menuBar.addItem("View", null);
		MenuItem axisOption = viewItem.addItem("Show axis", showAxisCommand);
		axisOption.setCheckable(true);
		MenuItem gridOption = viewItem.addItem("Show grid", showGridCommand);
		gridOption.setCheckable(true);
		MenuItem boundaryOption = viewItem.addItem("Show boundaries", boundaryIdicatorCommand);
		boundaryOption.setCheckable(true);
	}
	
	private void initToolsItem(){
		final MenuBar.MenuItem toolsItem = menuBar.addItem("Tools", null);
	}
	
	private void initHelpItem(){
		final MenuBar.MenuItem helpItem = menuBar.addItem("Help", null);
		MenuItem helpOption = helpItem.addItem("Help Contents", helpCommand);
		MenuItem aboutOption = helpItem.addItem("About", aboutCommand);
	}
	
}
